package com.hengxinguotong.zhihuichengjian.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.ui.app.BaseFragment;
import com.hengxinguotong.zhihuichengjian.ui.GuideActivity;
import com.hengxinguotong.zhihuichengjian.ui.LoginActivity;
import com.hengxinguotong.zhihuichengjian.utils.SPUtil;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/26.
 */

public class GuidePageFragment extends BaseFragment implements View.OnClickListener {

    public static GuidePageFragment newInstance(int index){
        Bundle bundle = new Bundle();
        bundle.putInt("index",index);
        GuidePageFragment fragment = new GuidePageFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    private View rootView;
    @BindView(R.id.back_ground)
    RelativeLayout backGround;
    @BindView(R.id.tag_tv)
    HXTextView tagTv;

    private GuideActivity guideActivity;
    private float x1, y1, x2, y2;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_guidepage, null);
            ButterKnife.bind(this, rootView);
            guideActivity = (GuideActivity) getActivity();
            Bundle bundle = getArguments();
            int index = bundle.getInt("index", 0);
            if(index == 0){
                backGround.setBackgroundResource(R.mipmap.guide_page_bg1);
                tagTv.setVisibility(View.GONE);
            }else if(index == 1){
                backGround.setBackgroundResource(R.mipmap.guide_page_bg2);
                tagTv.setVisibility(View.VISIBLE);
                backGround.setOnClickListener(this);
            }
        }else {
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (parent != null) {
                parent.removeView(rootView);
            }
        }
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onClick(View v) {
        SPUtil.put(getContext(), "isFirst", false);
        Intent intent = new Intent(guideActivity, LoginActivity.class);
        startActivity(intent);
        getActivity().finish();
    }

    @Override
    public void onLazyLoad() {

    }
}
